using System;
using System.Xml;
using System.Collections;

namespace Scenario.Modules.FormHelper
{
	
	public class XMLFormAttribute : bOSdotNET.XML.Data.XMLObject
	{
		public const string MAIN_NODE	= "FormAttribute";

		private const string NAME_ATTRIBUTE			= "Name";
		private const string RESOURCE_ATTRIBUTE		= "Resource";
		private const string DIRECTION_ATTRIBUTE	= "Direction";
		private const string STATEMENT_NODE			= "Statement";

		public const string INPUT_DIRECTION_VALUE	= "IN";
		public const string OUTPUT_DIRECTION_VALUE	= "OUT";
		
		public const string RESOURCE_SQL_VALUE		=	"SQL";
		public const string RESOURCE_PROCESS_VALUE	=	"SCENARIO";
		public const string RESOURCE_DOCUMENT_VALUE	=	"DOCUMENT";
		public const string RESOURCE_XSLT_VALUE		=	"XSLT";


		
		/** FIELDS **/

		public string sResource;
		public string sDirection;
		public string sName;
		public string sStatement;

		/** CONSTRUCTORS **/

		/** CONSTRUCTOR Width simple Property **/
		public XMLFormAttribute()
		{
			this.Init();
		}

		/** CONSTRUCTOR Width XML parsering**/
		public XMLFormAttribute(System.Xml.XmlNode node)
		{
			this.Parse(node);
		}

		override public void Init()
		{
			this.sResource= string.Empty;
			sDirection= string.Empty;
			sName= string.Empty;
			sStatement= string.Empty;
		

		}

		/** PROPERTIES **/


		public string Resource 
		{
			get { return sResource; }
			set { sResource = value; }
		}

		public string Direction 
		{
			get { return sDirection; }
			set { sDirection = value; }
		}

		public string Name 
		{
			get { return sName; }
			set { sName = value; }
		}

		public string Statement 
		{
			get { return sStatement; }
			set { sStatement = value; }
		}
		
		/** INSTANCE METHODS **/

		/** Parsering method for filling the entity **/
		override public void Parse(System.Xml.XmlNode node2Parse)
		{
			this.Init();

			System.Xml.XmlNode node;
			

			/** find the attributes situated on the root tag **/
			for ( int i=0; i<node2Parse.Attributes.Count;i++)
			{
				node = node2Parse.Attributes.Item(i);

				switch ( node.Name )
				{
					case XMLFormAttribute.NAME_ATTRIBUTE:
						sName = node.InnerText;
						break;
					case XMLFormAttribute.DIRECTION_ATTRIBUTE:
						sDirection = node.InnerText;
						break;
					case XMLFormAttribute.RESOURCE_ATTRIBUTE:
						this.sResource= node.InnerText;
						break;
					
				}
			}

			/** find the sub tags witch contains action values **/
			for ( int i=0; i<node2Parse.ChildNodes.Count; i++)
			{
				node = node2Parse.ChildNodes[i];

				switch (node.Name) 
				{
					case XMLFormAttribute.STATEMENT_NODE:
						sStatement=node.InnerText;
						break;

				} 
			}
		}

		override public bOSdotNET.XML.XMLNode GetXMLNode()
		{
			bOSdotNET.XML.XMLNode xmlNode = new bOSdotNET.XML.XMLNode(XMLFormAttribute.MAIN_NODE);
			xmlNode.AddAttribute ( new bOSdotNET.XML.XMLAttribute (XMLFormAttribute.NAME_ATTRIBUTE, sName) );
			xmlNode.AddAttribute ( new bOSdotNET.XML.XMLAttribute (XMLFormAttribute.DIRECTION_ATTRIBUTE, sDirection) );
			xmlNode.AddAttribute ( new bOSdotNET.XML.XMLAttribute (XMLFormAttribute.RESOURCE_ATTRIBUTE, this.sResource) );
			xmlNode.AddNode ( new bOSdotNET.XML.XMLNode (XMLFormAttribute.STATEMENT_NODE, sStatement) );
						
			return xmlNode;
		}
		/** STATIC METHODS **/

		/** no static methods **/
	}
}
